﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US" xml:lang="en">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
    <title>Time Tracker - Home</title>
    <script type="text/javascript" src="script.js"></script>
    <link rel="stylesheet" href="style.css" type="text/css" media="screen" />
    <link rel="shortcut icon" href="/timetracker.ico" />
    <link rel="icon" type="image/vnd.microsoft.icon" href="timetracker.ico" />
    <!--[if IE 6]><link rel="stylesheet" href="style.ie6.css" type="text/css" media="screen" /><![endif]-->
    <!--[if IE 7]><link rel="stylesheet" href="style.ie7.css" type="text/css" media="screen" /><![endif]-->
</head>
<body>
    <form id="form1" runat="server">
    <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
    </asp:ToolkitScriptManager>
    <div id="art-page-background-simple-gradient">
    </div>
    <div id="art-page-background-glare">
    </div>
    <div id="art-main">
        <div class="art-Sheet">
            <div class="art-Sheet-tl">
            </div>
            <div class="art-Sheet-tr">
            </div>
            <div class="art-Sheet-bl">
            </div>
            <div class="art-Sheet-br">
            </div>
            <div class="art-Sheet-tc">
            </div>
            <div class="art-Sheet-bc">
            </div>
            <div class="art-Sheet-cl">
            </div>
            <div class="art-Sheet-cr">
            </div>
            <div class="art-Sheet-cc">
            </div>
            <div class="art-Sheet-body">
                <div class="art-nav">
                    <div class="l">
                    </div>
                    <div class="r">
                    </div>
                    <ul class="art-menu">
                        <li>
                            <asp:HyperLink ID="HyperLinkMain" runat="server" NavigateUrl="~/Default.aspx" class="active"><span class="l"></span><span class="r"></span><span class="t">Home</span></asp:HyperLink>
                        </li>
                        <%if (User.IsInRole("Administrator"))
                          { %>
                        <li>
                            <asp:HyperLink ID="HyperLinkEmployee" runat="server" NavigateUrl="~/Users.aspx"><span class="l"></span><span class="r"></span><span class="t">Manage Users</span></asp:HyperLink>
                        </li>
                        <li>
                            <asp:HyperLink ID="HyperSettings" runat="server" NavigateUrl="~/Settings.aspx"><span class="l"></span><span class="r"></span><span class="t">Manage Settings</span></asp:HyperLink>
                        </li>
                        <%} %>
                        <li>
                            <asp:LinkButton ID="LinkButtonLogOut" runat="server" OnClick="Click_Logout"><span class="l"></span><span class="r"></span><span class="t">Log Out</span></asp:LinkButton>
                        </li>
                    </ul>
                </div>
                <div class="art-Header">
                    <div class="art-Header-jpeg">
                    </div>
                    <div class="art-Logo">
                        <h1 id="name-text" class="art-Logo-name">
                            <a href="#">Time Tracker</a></h1>
                    </div>
                </div>
                <div class="art-contentLayout">
                    <div class="art-sidebar1">
                        <div class="art-Block">
                            <div class="art-Block-body">
                                <div class="art-BlockHeader">
                                    <div class="l">
                                    </div>
                                    <div class="r">
                                    </div>
                                    <div class="art-header-tag-icon">
                                        <div class="t">
                                            Time Tracking</div>
                                    </div>
                                </div>
                                <div class="art-BlockContent">
                                    <div class="art-BlockContent-body">
                                        <div>
                                           <asp:TreeView ID="TreeView1" runat="server" OnSelectedNodeChanged="Tree_Clicked">
                                                <Nodes>
                                                    <asp:TreeNode Text="Customer List" Value="Customers">
                                                        <asp:TreeNode Text="Create New Customer" Value="Create New Customer"></asp:TreeNode>
                                                    </asp:TreeNode>
                                                    <asp:TreeNode Text="Task List" Value="Task">
                                                        <asp:TreeNode Text="Create a New Task" Value="Create a New Task"></asp:TreeNode>
                                                    </asp:TreeNode>
                                                    <asp:TreeNode Text="Reporting" Value="Reporting"></asp:TreeNode>
                                                </Nodes>
                                            </asp:TreeView>
                                        </div>
                                        <div class="cleared">
                                        </div>
                                    </div>
                                </div>
                                <div class="cleared">
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="art-content">
                        <div class="art-Post">
                            <div class="art-Post-body">
                                <asp:UpdatePanel ID="UpdatePanelContent" runat="server">
                                    <ContentTemplate>
                                        <asp:LinqDataSource ID="LinqDataSourceCustomer" runat="server" ContextTypeName="TimeTrackerDataContext"
                                            EnableDelete="True" EnableInsert="True" EnableUpdate="True" OrderBy="customerName"
                                            TableName="Customers">
                                        </asp:LinqDataSource>
                                        <asp:GridView ID="GridViewCustomers" runat="server" AutoGenerateColumns="False" DataSourceID="LinqDataSourceCustomer"
                                            CellPadding="4" DataKeyNames="id" ForeColor="#333333" GridLines="None" AllowSorting="True"
                                            Width="100%" EnableModelValidation="True">
                                            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                                            <Columns>
                                                <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" 
                                                    ButtonType="Button">
                                                <HeaderStyle Width="125px" />
                                                <ItemStyle HorizontalAlign="Left" Width="125px" Wrap="False" />
                                                </asp:CommandField>
                                                <asp:BoundField DataField="customerName" HeaderText="Name" 
                                                    SortExpression="customerName" >
                                                <HeaderStyle HorizontalAlign="Left" />
                                                <ItemStyle HorizontalAlign="Left" VerticalAlign="Middle" Width="450px" />
                                                </asp:BoundField>
                                                <asp:TemplateField HeaderText="Tasks" SortExpression="Projects">
                                                    <EditItemTemplate>
                                                        <asp:Label ID="Label1" runat="server" Text='<%# Eval("Projects.Count") %>'></asp:Label>
                                                    </EditItemTemplate>
                                                    <ItemTemplate>
                                                        <asp:Label ID="Label1" runat="server" Text='<%# Eval("Projects.Count") %>'></asp:Label>
                                                    </ItemTemplate>
                                                    <HeaderStyle HorizontalAlign="Left" VerticalAlign="Middle" Width="75px" />
                                                    <ItemStyle HorizontalAlign="Left" VerticalAlign="Middle" Width="75px" />
                                                </asp:TemplateField>
                                            </Columns>
                                            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                                            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                                            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                                            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                                            <EditRowStyle BackColor="#999999" />
                                            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                                        </asp:GridView>
                                        <asp:GridView ID="GridViewProjects" runat="server" AutoGenerateColumns="False" DataKeyNames="id"
                                            DataSourceID="LinqDataSourceProjects" EmptyDataText="There currently aren't any tasks available in the system. Please create one."
                                            Visible="False" AllowPaging="True" CellPadding="4" ForeColor="#333333" GridLines="None"
                                            AllowSorting="True" Width="100%" OnSelectedIndexChanged="SelectProject" EnableModelValidation="True">
                                            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                                            <Columns>
                                                <asp:CommandField ShowDeleteButton="True" ShowSelectButton="True" ButtonType="Button"/>
                                                <asp:BoundField DataField="id" HeaderText="ID" SortExpression="id" InsertVisible="False"
                                                    ReadOnly="True" />
                                                <asp:BoundField DataField="name" HeaderText="Name" SortExpression="name" />
                                                <asp:TemplateField HeaderText="Customer" SortExpression="customerID">
                                                    <EditItemTemplate>
                                                        <asp:Label ID="Label1" runat="server" Text='<%# Eval("Customer.customerName") %>'></asp:Label>
                                                    </EditItemTemplate>
                                                    <ItemTemplate>
                                                        <asp:Label ID="Label1" runat="server" Text='<%# Eval("Customer.customerName") %>'></asp:Label>
                                                    </ItemTemplate>
                                                </asp:TemplateField>
                                                <asp:TemplateField HeaderText="End Date" SortExpression="endDate">
                                                    <EditItemTemplate>
                                                        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("endDate","{0:MM/dd/yyyy}") %>'></asp:TextBox>
                                                    </EditItemTemplate>
                                                    <ItemTemplate>
                                                        <asp:Label ID="Label2" runat="server" Text='<%# Eval("endDate","{0:MM/dd/yyyy}") %>'></asp:Label>
                                                    </ItemTemplate>
                                                </asp:TemplateField>
                                                <asp:TemplateField HeaderText="Time">
                                                    <ItemTemplate>
                                                        <%# GetTotalTime((int)Eval("id")) %>
                                                    </ItemTemplate>
                                                </asp:TemplateField>
                                            </Columns>
                                            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                                            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                                            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                                            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                                            <EditRowStyle BackColor="#999999" />
                                            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                                        </asp:GridView>
                                        <asp:LinqDataSource ID="LinqDataSourceProjects" runat="server" ContextTypeName="TimeTrackerDataContext"
                                            TableName="Projects" EnableDelete="True" EnableInsert="True" EnableUpdate="True">
                                        </asp:LinqDataSource>
                                        <asp:Panel ID="Panel1" runat="server" Visible="False">
                                            <asp:Label ID="LabelNewCustomer" runat="server" CssClass="art-PostHeader" Text="Create a new customer"></asp:Label>
                                            <br />
                                            <asp:Label ID="LabelCustomerName" runat="server" Text="Name"></asp:Label>
                                            &nbsp;
                                            <asp:TextBox ID="TextBoxCustomerName" runat="server"></asp:TextBox>
                                            &nbsp;&nbsp;
                                            <asp:Button ID="ButtonCustomerCreate" runat="server" OnClick="AddCustomer" Text="Submit" />
                                            &nbsp;
                                        </asp:Panel>
                                        <asp:Panel ID="PanelProject" runat="server" Visible="False" Height="400">
                                            <asp:Label ID="Label2" runat="server" CssClass="art-PostHeader" Text="Create a new task"></asp:Label><asp:Panel
                                                            ID="PanelAddTimeEntries" runat="server">
                                                            <div style="float: right; width: 150px;">
                                                                Add Time Entry<br />
                                                                <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="TextBoxEntry"
                                                                    ErrorMessage="RegularExpressionValidator" ValidationExpression="\d*\.*\d*"></asp:RegularExpressionValidator>
                                                                <asp:TextBox ID="TextBoxEntry" runat="server" Width="62px"></asp:TextBox>
                                                                <asp:Button ID="ButtonAddTimeEntry" runat="server" Text="Add" OnClick="AddEntry" />
                                                            </div>
                                                        </asp:Panel>
                                                        <table>
                                                            <tr>
                                                                <td align="right">
                                                                    Name:
                                                                </td>
                                                                <td>
                                                                    <asp:TextBox ID="TextBoxProject" runat="server"></asp:TextBox><asp:HiddenField ID="ProjectID"
                                                                        runat="server" />
                                                                    <asp:RequiredFieldValidator ID="RequiredFieldValidatorProjectName" runat="server"
                                                                        ErrorMessage="Task Name Required" ValidationGroup="ProjectCreate" ControlToValidate="TextBoxProject"></asp:RequiredFieldValidator>
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td align="right">
                                                                    Customer:
                                                                </td>
                                                                <td>
                                                                    <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="LinqDataSourceCustomer"
                                                                        DataTextField="customerName" DataValueField="id">
                                                                    </asp:DropDownList>
                                                                    <asp:Label ID="TextBoxCustomer" runat="server" Visible="False"></asp:Label>
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td align="right">
                                                                    Start Date:
                                                                </td>
                                                                <td>
                                                                    <asp:TextBox ID="TextBoxStartDate" runat="server"></asp:TextBox>
                                                                    <asp:CalendarExtender ID="CalendarExtenderStartDate" runat="server" TargetControlID="TextBoxStartDate">
                                                                    </asp:CalendarExtender>
                                                                    <asp:RequiredFieldValidator ID="RequiredFieldValidatorStartDate" runat="server" ErrorMessage="Please select a Start Date"
                                                                        ControlToValidate="TextBoxStartDate" ValidationGroup="ProjectCreate"></asp:RequiredFieldValidator>
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td align="right">
                                                                    End Date:
                                                                </td>
                                                                <td>
                                                                    <asp:TextBox ID="TextBoxEndDate" runat="server"></asp:TextBox>
                                                                    <asp:CalendarExtender ID="CalendarExtenderEndDate" runat="server" TargetControlID="TextBoxEndDate">
                                                                    </asp:CalendarExtender>
                                                                    <asp:RequiredFieldValidator ID="RequiredFieldValidatorEndDate" runat="server" ErrorMessage="Please select a Start Date"
                                                                        ControlToValidate="TextBoxEndDate" ValidationGroup="ProjectCreate"></asp:RequiredFieldValidator>
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td align="right">
                                                                    Elapsed Time:
                                                                </td>
                                                                <td>
                                                                    <asp:TextBox ID="TextBoxElapsedTime" runat="server" ReadOnly="True" BackColor="#CCD5E1" />
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td colspan="2">
                                                                </td>
                                                            </tr>
                                                        </table>
                                                        <asp:Label ID="LabeltimeSheet" runat="server" Text="Timesheet for task:"></asp:Label><br />
                                                        <asp:ListBox ID="ListBoxTimes" runat="server" Height="193px" Width="573px"></asp:ListBox>
                                                        <asp:Button ID="ButtonSubmit" runat="server" OnClick="AddProject" Text="Submit" ValidationGroup="ProjectCreate" />
                                                    </asp:Panel>
                                                    <asp:Panel ID="PanelReport" runat="server" Visible="False">
                                                        <asp:Label ID="Label7" runat="server" CssClass="art-PostHeader" Text="Task Report"></asp:Label>
                                                        <asp:DataList ID="DataList1" runat="server" CellPadding="4" DataSourceID="SqlDataSourceReport"
                                                             Width="100%" DataKeyField="id">
                                                            <FooterStyle  Font-Bold="True" ForeColor="White" />
                                                            <AlternatingItemStyle BackColor="White"  />
                                                            <ItemStyle   />
                                                            <SelectedItemStyle  Font-Bold="True"  />
                                                            <HeaderStyle  Font-Bold="True" ForeColor="White" />
                                                            <ItemTemplate>
                                                                <asp:Label ID="idLabel" runat="server" Text='<%# Eval("id") %>' />
                                                                - <b>
                                                                    <asp:Label ID="nameLabel" runat="server" Text='<%# Eval("name") %>' /></b> -
                                                                <asp:Label ID="customerNameLabel" runat="server" Text='<%# Eval("customerName") %>' />
                                                                <br />
                                                                <asp:Label ID="startDateLabel" runat="server" Text='<%# Eval("startDate", "{0:MM/dd/yyyy}") %>' />
                                                                -
                                                                <asp:Label ID="endDateLabel" runat="server" Text='<%# Eval("endDate", "{0:MM/dd/yyyy}") %>' />
                                                                <br />
                                                                Total Hours:
                                                                <asp:Label ID="timeTotalLabel" runat="server" Text='<%# GetTotalTime((int)Eval("id")) %>' />
                                                                <br />
                                                                <br />
                                                            </ItemTemplate>
                                                        </asp:DataList>
                                                        <asp:SqlDataSource ID="SqlDataSourceReport" runat="server" ConnectionString="<%$ ConnectionStrings:TimeTrackerConnectionString1 %>"
                                                            SelectCommand="SELECT (SELECT customerName FROM Customer WHERE (id = Project.customerID)) AS customerName, id, name, startDate, endDate, timeTotal FROM Project ORDER BY customerName">
                                                        </asp:SqlDataSource>
                                                    </asp:Panel>
                                                </ContentTemplate>
                                                <Triggers>
                                                    <asp:AsyncPostBackTrigger ControlID="TreeView1" EventName="SelectedNodeChanged" />
                                                </Triggers>
                                            </asp:UpdatePanel>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="cleared">
                </div>
                <div class="art-Footer">
                    <div class="art-Footer-inner">
                        <div class="art-Footer-text">
                            <p>
                                <a href="#">Terms of Use</a> | <a href="#">Privacy Statement</a><br />
                                Copyright &copy;
                                <%=System.DateTime.Today.Year.ToString() %>. All Rights Reserved.</p>
                        </div>
                    </div>
                    <div class="art-Footer-background">
                    </div>
                </div>
                <div class="cleared">
                </div>
            </div>
        </div>
        <div class="cleared">
        </div>
    </div>
    </form>
</body>
</html>
